class AutoAccessWorker < ApplicationWorker

  def perform(wuser_ids, sns_type)
    Sidekiq.redis do |redis|
      wuser_ids = wuser_ids.split(',')
      if wuser_ids.empty?
        AutoAccessWorker.perform_in(18.hours, Utility.const_get(sns_type.capitalize).active.map(&:_id).join(','), sns_type)
      else
        begin
          wid = wuser_ids.pop
          Utility.const_get(sns_type.capitalize).where(:_id => wid ).first.auto_access
        rescue
          wuser_ids.insert(0, wid)
        end
        pid = AutoAccessWorker.perform_at(30.minutes, wuser_ids.join(','), sns_type)
        redis.set "flowy:auto_access:#{sns_type}", (pid || true)
      end
    end

  end

end